<?php $this->load->view('partial/head'); ?>

<h2><?= $mode . " KUISIONER" ?></h2>

<form method="post" action="<?= base_url()."index.php/cs/save_kuisioner" ?>">
	<input type="hidden" name="mode" value="<?= $mode ?>" />
	<?php if($mode == 'EDIT'){ ?>
		<input type="hidden" name="id_kuisioner" value="<?= $detail['id_kuisioner'] ?>" />
	<?php } ?>
	
	<table cellpadding="10">
		<tr>
			<td>Pertanyaan</td>
			<td><input name="pertanyaan" size="50" value="<?=($mode == 'EDIT' ? $detail['pertanyaan'] : '')?>" /></td>
		</tr>
		<tr>
			<td>Status</td>
			<td>
				<select name="status">
					<option value="<?=STATUS_KUISIONER_PUBLISH?>">Publish</option>
					<option value="<?=STATUS_KUISIONER_DRAFT?>">Draft</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>Pilihan Jawaban</td>
			<td><a id="add-pilihan" href="#">(+) Tambah Pilihan Jawaban</a><br/>
				<?php if($mode == 'ADD'){ ?>
					<input type="text" name="pilihan[]" /><input type="hidden" name="id_pilihan[]"/></br>
				<?php }else{ 
					foreach($pilihan as $pil){ ?>
						<input type="text" name="pilihan[]" value="<?=$pil['isi']?>" /></br>
						<input type="hidden" name="id_pilihan[]" value="<?=$pil['id_pilihan']?>" />
				<?php } 
				} ?>
				<div id="pilihan-wrap"></div>
			</td>
		</tr>
		<tr>
			<td></td>
			<td>
				<a href="<?= base_url()."index.php/cs/kuisioner" ?>"><input type="button" value="Kembali" /></a>
				<input type="submit" value="Simpan" />
			</td>
		</tr>
	</table>
</form>

<script>
$(function(){
	$('#add-pilihan').click(function(e){
		e.preventDefault();
		$('#pilihan-wrap').append('<input type="text" name="pilihan[]" /><input type="hidden" name="id_pilihan[]" /></br>');
	});
});
</script>